//
//  THFlowEarnManaulPublishVC.m
//  YJB
//
//  Created by 中电大维 on 2017/1/16.
//  Copyright © 2017年 YJB. All rights reserved.
//  自动赚钱的发布任务

#import "THFlowEarnManaulPublishVC.h"
#import "THVipModel.h"

//@"VIP用户: 发布任务总金额优惠10%" 显示字样的tag
#define VIP_TAG 333

@interface THFlowEarnManaulPublishVC ()<UITextFieldDelegate,UIScrollViewDelegate,UIAlertViewDelegate,UITextViewDelegate>
@property(nonatomic, strong)UIView *footView;
//@property(nonatomic, copy)NSString *goldCount;
@property(nonatomic, strong)THVipModel *vipModel;
@end

@implementation THFlowEarnManaulPublishVC
{
    NSArray     *_titles;
    NSArray     *_placeholders;
    NSInteger   _selectRow;
    UITextView *_titleView;
    UITextView *_urlView;
    UITextField *_numField;
    UITextField *_upriceField;
    UITextField *_sumField;
    UILabel     *_vipsumlabel;
    CGFloat _titlewidth;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    if (self.isEditDetail) {
        self.title = @"修改发布任务";
    }else{
        self.title = @"发布任务";
    }
    _selectRow = 0;
    _titles = [[NSArray alloc] initWithObjects:@"任务标题",@"任务网址",@"名额数量",@"任务单价",@"任务总价", nil];
    _placeholders = [[NSArray alloc] initWithObjects:@"请输入任务标题",@"请输入任务网址",@"不低于1000个",@"请输入任务单价",@"请输入任务总价",nil];
    _titlewidth = [NSString widthForString:[NSString stringWithFormat:@"%@",_titles[0]] fontSize:16 andHeight:15];
    
    [self createTextView];
    [self createTextField];
    
    self.tableView.tableFooterView = [UIView new];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    //self.tableView.scrollEnabled = NO;
    [self.tableView setSeparatorColor:[UIColor colorWithHexString:@"e5e5e5"]];
    //[self.tableView setSeparatorColor:[UIColor colorWithHexString:@"eeeeee"]];
    self.tableView.backgroundColor = kUIColorFromRGB(0xeeeeee);
    [self.view addSubview:self.footView];
    
    [self getprice];
    [self getCurrentGoldCount];
}
- (void)getCurrentGoldCount
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSString *userName = [YJUserDefaultTool readUserName];
    NSString *md5Key = [YJUserDefaultTool readKeyID];
    params[@"action"] = @"get_userbenefe_val";
    params[@"makegold"] = @{@"username":userName,
                            @"user_info":userName,
                            @"phone_info":@"iOS",
                            @"md5_key":md5Key};
    [YJNetworkTool postWithUrl:THURL(@"configure.php") parameters:params success:^(id responseObject) {
        [self.tableView.mj_header endRefreshing];
        NSString *code = responseObject[@"return"][@"code"];
        if (code.integerValue == 200)
        {
            NSDictionary *dict = responseObject[@"return"][@"data"];
            [self.vipModel setValuesForKeysWithDictionary:dict];
            UILabel *label = [self.footView viewWithTag:VIP_TAG];
            label.text = [NSString stringWithFormat:@"VIP用户: 发布任务总金额优惠%.0f%%",[self.vipModel.vip_benef floatValue]*100];
        }
    } failure:^(NSError *error) {
        [self getCurrentGoldCount];
    }];
}
- (void)getprice
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSString *userName = [YJUserDefaultTool readUserName];
    NSString *md5Key = [YJUserDefaultTool readKeyID];
    params[@"action"] = @"get_publishgold_one";
    params[@"makegold"] = @{@"user_info":userName,
                            @"phone_info":@"iOS",
                            @"md5_key":md5Key};
    [YJNetworkTool postWithUrl:THURL(@"traffic.php") parameters:params success:^(id responseObject) {
        [self.tableView.mj_header endRefreshing];
        NSString *code = responseObject[@"return"][@"code"];
        if (code.integerValue == 200)
        {
            NSString *price = responseObject[@"return"][@"data"][@"gold_one"];
            _upriceField.text = [NSString stringWithFormat:@"%@",price];
        }
        else if(code.integerValue == 500)
            
            [self.tableView reloadData];
    } failure:^(NSError *error) {
        [MBProgressHUD showError:@"网络不佳，稍后重试" toView:self.view];
    }];
    
}

- (void)textFieldWithText:(UITextField *)textField
{
    if (textField.tag == 2&&textField.text.length == 0) {
        textField.text = @"http://";
    }
}

- (void)openVipClick:(UIButton *)button
{
    [self setEndViewEditing:YES];
}
- (void)lookprotolClick:(UIButton *)button
{
    [self setEndViewEditing:YES];
}

- (void)publishTaskClick:(UIButton *)button
{
    [self setEndViewEditing:YES];
    
    NSArray *textFields = @[_titleView,_urlView,_numField,_upriceField,_sumField];
    for (int i = 0; i < _placeholders.count; i ++)
    {
        if (0 == i || 1 == i) {
            UITextView *textView = textFields[i];
            if ([textView.text isEqualToString:_placeholders[i]]) {
                [MBProgressHUD showError:_placeholders[i] toView:self.view];
                return;
            }
        }
        
        UITextField *textField = textFields[i];
        if (textField.text.length == 0)
        {
            if (i == 2 && [textField.text floatValue] < 20) {
                [MBProgressHUD showError:[NSString stringWithFormat:@"请输入名额数量"] toView:self.view];
                return;
            }
           
        }
        if (i == 2 && [textField.text intValue] < 1000) {
            [MBProgressHUD showError:[NSString stringWithFormat:@"名额数量%@",_placeholders[i]] toView:self.view];
            return;
        }
        if (![textField.text isUrlString] && i == 1) {
             [MBProgressHUD showError:@"任务网址格式不对"];
            return;
        }
    }
    
    if (self.isEditDetail) {
        [self editPublishTask];
    }else{
        [self publishTask];
    }
}

- (void)editPublishTask
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSString *userName = [YJUserDefaultTool readUserName];
    NSString *md5Key = [YJUserDefaultTool readKeyID];
    NSString *url = THURL(@"traffic.php");
    params[@"action"] = @"set_surf_edit";
    params[@"makegold"] = @{@"task_id":self.model.ID,
                            @"username":userName,
                            @"sitename":self.model.sitename,
                            @"url":self.model.url,
                            @"user_info":userName,
                            @"phone_info":@"iOS",
                            @"md5_key":md5Key};
    
    [YJNetworkTool postWithUrl:url parameters:params success:^(id responseObject) {
        NSString *code = responseObject[@"return"][@"code"];
        if (code.integerValue == 200)
        {
            [MBProgressHUD showSuccess:@"修改任务成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [MBProgressHUD showError:responseObject[@"return"][@"message"]];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD showError:@"网络不佳，稍后重试" toView:self.view];
    }];
}


//自动流量赚钱 （6）发布流量任务
- (void)publishTask
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSString *userName = [YJUserDefaultTool readUserName];
    NSString *md5Key = [YJUserDefaultTool readKeyID];
    params[@"action"] = @"set_surf_add";
    params[@"makegold"] = @{@"username":userName,
                            @"sitename":_titleView.text,
                            @"url":_urlView.text,
                            @"surflimit":_numField.text,
                            @"user_info":userName,
                            @"phone_info":@"iOS",
                            @"md5_key":md5Key};
    [YJNetworkTool postWithUrl:THURL(@"traffic.php") parameters:params success:^(id responseObject) {
        NSString *code = responseObject[@"return"][@"code"];
        if (code.integerValue == 200)
        {
            [MBProgressHUD showSuccess:@"发布成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }
        else if(code.integerValue == 500)
             [MBProgressHUD showError:[[responseObject objectForKey:@"return"] objectForKey:@"message"]];
    } failure:^(NSError *error) {
        [MBProgressHUD showError:@"网络不佳，稍后重试" toView:self.view];
    }];
}


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (textField.text.length>30 && (textField.tag == 1 || textField.tag == 2)) {
        
        return NO;
    }
    return YES;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if ((!self.isEditDetail&&(textField.tag == 5 || textField.tag == 4))||(self.isEditDetail && (textField.tag == 5 || textField.tag == 4 || textField.tag == 3))) {
        return NO;
    }
    return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [textField  resignFirstResponder];
    [self calculateTatolGold];
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if ([textView.text hasPrefix: @"请输入"]) {
        if (textView.tag == 1) {
            textView.text = nil;
        }else{
            [self setStringTextView:textView WithText:@"http://"];
        }
    }
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
    if (!textView.text.length||[textView.text isEqualToString:@"http://"]) {
        [self setStringTextView:textView WithText:nil];
    }
}

- (void)textViewDidChange:(UITextView *)textView
{
    NSString *placeholder = _placeholders[textView.tag-1];
    if ([textView.text hasPrefix: @"请输入"]) {
        if (textView.text.length < placeholder.length) {
            textView.text = nil;
        }else{
            [self setStringTextView:textView WithText:[textView.text substringFromIndex:placeholder.length]];
        }
    }
    if (textView.text.length > 30) {
        [self setStringTextView:textView WithText:[textView.text substringToIndex:30]];
    }else if(textView.text > 0){
        [self setStringTextView:textView WithText:textView.text];
    }
}

- (void)setStringTextView:(UITextView *)textView WithText:(NSString *)text
{
    if (text.length) {
        textView.text = text;
        textView.textColor = kUIColorFromRGB(0x333333);
    }else{
        textView.text = _placeholders[textView.tag-1];
        textView.textColor = [UIColor colorWithRed:192/255.0 green:192/255.0  blue:198/255.0 alpha:1];
    }
}

- (void)setVipsum
{
    if (_numField.text.length && _sumField.text.length) {
        
        if (_isEditDetail) {
            _vipsumlabel.text = [NSString stringWithFormat:@"%@",self.vipModel.vip_benef];
        }else{
            if ([self.vipModel.isvip intValue] == 2 && [self.vipModel.autotraff_vip_need floatValue] <= [_sumField.text floatValue]) {
                _vipsumlabel.text = [NSString stringWithFormat:@"%.2f",[_numField.text floatValue]*[_upriceField.text floatValue]*[self.vipModel.vip_benef floatValue]];
            }else{
                _vipsumlabel.text = @"0";
            }
        }
        _vipsumlabel.textColor = kUIColorFromRGB(0xff783c);
    }else{
        _vipsumlabel.textColor = kUIColorFromRGB(0x666666);
        _vipsumlabel.text = @"VIP优惠额";
    }
}

- (void)calculateTatolGold
{
    float num = [self.vipModel.isvip intValue]==1?1:(1-[self.vipModel.vip_benef floatValue]);
    float total = [_numField.text floatValue]*[_upriceField.text floatValue]*num;
    _sumField.text = [NSString stringWithFormat:@"%.2f",total];
    
    [self setVipsum];
    if (total > [self.vipModel.totalgold floatValue]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您的金币数量已不足" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"前往充值", nil];
        [alert show];
    }
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {// 前往充值
        
    }else if(!buttonIndex){
        _numField.text = nil;
        _sumField.text = nil;
        [self setVipsum];
    }
}

- (void)setEndViewEditing:(BOOL)isEdit
{
    [self.tableView endEditing:YES];
    [self.view endEditing:YES];
    [self calculateTatolGold];
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self setEndViewEditing:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _titles.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat titlewidth = [NSString widthForString:[NSString stringWithFormat:@"%@",_titles[0]] fontSize:16 andHeight:15];
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FlowEarnPublishTaskID"];
    if (!cell) {
        cell = [[UITableViewCell alloc] init];
        cell.textLabel.textColor = kUIColorFromRGB(0x333333);
        cell.textLabel.font = FONT(16);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.text = [NSString stringWithFormat:@"%@",_titles[indexPath.row]];
        
        if (indexPath.row < 2) {
            UITextView *textView = [[UITextView alloc] init];
            switch (indexPath.row) {
                case 0:
                    textView = _titleView;
                    if (_isEditDetail) {
                        [self setStringTextView:textView WithText:[NSString stringWithFormat:@"%@",self.model.sitename]];
                    }
                    break;
                case 1:
                    textView = _urlView;
                    if (_isEditDetail) {
                        [self setStringTextView:textView WithText:[NSString stringWithFormat:@"%@",self.model.url]];
                    }
                    break;
            }
            [cell addSubview:textView];
            [textView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(cell.mas_centerY);
                make.left.mas_equalTo(_titlewidth+30);
                make.right.mas_equalTo(-12);
                make.height.mas_equalTo(36);
            }];
            
            switch (indexPath.row) {
                case 0:
                    _titleView = textView;
                    if (_isEditDetail) {
                        [self setStringTextView:textView WithText:[NSString stringWithFormat:@"%@",self.model.sitename]];
                    }
                    break;
                case 1:
                    _urlView = textView;
                    if (_isEditDetail) {
                        [self setStringTextView:textView WithText:[NSString stringWithFormat:@"%@",self.model.url]];
                    }
                    break;
            }
            
        }
        if (_titles.count > indexPath.row && indexPath.row >= 2) {
        
            UITextField *textfield = [[UITextField alloc] init];
            switch (indexPath.row) {
                case 2:
                    textfield = _numField;
                    textfield.text = self.isEditDetail? [NSString stringWithFormat:@"%@",self.model.total_num]:nil;
                    break;
                case 3:
                    textfield = _upriceField;
                    textfield.text = self.isEditDetail? [NSString stringWithFormat:@"%@",self.model.gold_one]:nil;
                    break;
                case 4:
                    textfield = _sumField;
                    if (self.isEditDetail) {
                        textfield.text = [NSString stringWithFormat:@"%.2f",[self.model.totalgold floatValue]];
                        _vipsumlabel.text = [NSString stringWithFormat:@"%@",self.vipModel.vip_benef];
                    }
                    
//                    if ([self.vipModel.isvip intValue] == 2) {
//                        textfield.text = self.isEditDetail? [NSString stringWithFormat:@"%.2f",[self.model.totalgold floatValue]*(1-[self.vipModel.vip_benef floatValue])]:nil;
//                    }else{
//                        textfield.text = self.isEditDetail? [NSString stringWithFormat:@"%@",self.model.totalgold]:nil;
//                    }
                    [self setVipsum];
                    break;
            }
            [cell addSubview:textfield];
            
            CGFloat rightspce = -12;
            if (indexPath.row == _titles.count-1) {
                rightspce -= 90;
                
                UIView *line = [[UIView alloc] init];
                UILabel *label = [[UILabel alloc] init];
                line.backgroundColor = kUIColorFromRGB(0xe5e5e5);
                label.font = FONT(15);
                label.textColor = kUIColorFromRGB(0x666666);
                label.textAlignment = NSTextAlignmentCenter;
                _vipsumlabel = label;
                if (_isEditDetail) {
                    label.text = [NSString stringWithFormat:@"%.2f",[self.model.benefe_val floatValue]];
                    label.textColor = kUIColorFromRGB(0xff783c);
                }else{
                    label.text = @"VIP优惠额";
                }
                
                [cell addSubview:line];
                [cell addSubview:label];
                
                [line mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.mas_equalTo(5);
                    make.bottom.mas_equalTo(-5);
                    make.width.mas_equalTo(0.5);
                    make.left.equalTo(textfield.mas_right);
                }];
                [label mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.bottom.mas_equalTo(0);
                    make.left.equalTo(textfield.mas_right).offset(5);
                    make.right.mas_equalTo(-12);
                }];
            }
            
            [textfield mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.bottom.mas_equalTo(0);
                make.left.mas_equalTo(titlewidth+30);
                make.right.mas_equalTo(rightspce);
            }];
            //此方法为关键方法
            [textfield addTarget:self action:@selector(textFieldWithText:) forControlEvents:UIControlEventEditingDidBegin];
        }
    }
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return TextField_RowHeight;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 6;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc]init];
    headerView.backgroundColor = kUIColorFromRGB(0xeeeeee);
    return headerView;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc]init];
    headerView.backgroundColor = kUIColorFromRGB(0xeeeeee);
    return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (tableView.tag == 100) {
        return 0;
    }
    return 1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self setEndViewEditing:YES];
}

- (void)createTextField
{
    for (int i = 2; i < _titles.count; i++) {
        UITextField *textfield = [[UITextField alloc] init];
        textfield.tag = i+1;
        textfield.font = FONT(16);
        textfield.textColor = kUIColorFromRGB(0x333333);
        textfield.placeholder = _placeholders[i];
        textfield.delegate = self;
        switch (i) {
            case 2:
                _numField = textfield;
                break;
            case 3:
                _upriceField = textfield;
                break;
            case 4:
                _sumField = textfield;
                break;
        }
    }
}

- (void)createTextView
{
    for (int i = 0; i < 2; i++) {
        UITextView *textView = [[UITextView alloc] init];
        textView.tag = i+1;
        textView.font = FONT(16);
        textView.textColor = [UIColor colorWithRed:192/255.0 green:192/255.0  blue:198/255.0 alpha:1];
        textView.text = _placeholders[i];
        textView.delegate = self;
        switch (i) {
            case 0:
                _titleView = textView;
                break;
            case 1:
                _urlView = textView;
                break;
        }
    }
}

- (UIView *)footView
{
    if (!_footView) {
        _footView = [[UIView alloc] init];
        UILabel *label1 = [[UILabel alloc] init];
        UILabel *label2 = [[UILabel alloc] init];
        UIButton *vipButton = [[UIButton alloc] init];
        UIButton *protolButton = [[UIButton alloc] init];
        UIButton *submitButton = [[UIButton alloc] init];
        
        [self.view addSubview:_footView];
        
        
        label1.textColor = kUIColorFromRGB(0x666666);
        label2.textColor = kUIColorFromRGB(0x666666);
        [vipButton setTitleColor:kUIColorFromRGB(0xff783c) forState:UIControlStateNormal];
        [protolButton setTitleColor:kUIColorFromRGB(0x0e41dc) forState:UIControlStateNormal];
        [submitButton setTitleColor:WHITECOLOR forState:UIControlStateNormal];
        [submitButton setBackgroundColor:kUIColorFromRGB(0xff783c)];
        
        label1.font = FONT(14);
        label2.font = FONT(14);
        vipButton.titleLabel.font = FONT(14);
        protolButton.titleLabel.font = FONT(14);
        submitButton.titleLabel.font = FONT(17);
        
        [vipButton.layer setMasksToBounds:YES];
        [vipButton.layer setCornerRadius:3.0];
        [vipButton.layer setBorderColor:kUIColorFromRGB(0xff783c).CGColor];
        [vipButton.layer setBorderWidth:0.5];
        
        [submitButton.layer setMasksToBounds:YES];
        [submitButton.layer setCornerRadius:3.0];
        [submitButton.layer setBorderColor:kUIColorFromRGB(0xff783c).CGColor];
        [submitButton.layer setBorderWidth:0.5];
        
        [vipButton addTarget:self action:@selector(openVipClick:) forControlEvents:UIControlEventTouchUpInside];
        [protolButton addTarget:self action:@selector(lookprotolClick:) forControlEvents:UIControlEventTouchUpInside];
        [submitButton addTarget:self action:@selector(publishTaskClick:) forControlEvents:UIControlEventTouchUpInside];
        
        NSString *str1 = @"VIP用户: 发布任务总金额优惠10%";
        NSString *str2 = @"点击【提交】即代表我已接受";
        NSString *vip = @"开通VIP";
        NSString *protol = @"《土豪任务管理协议》";
        label1.text = str1;
        label2.text  = str2;
        label1.tag = VIP_TAG;
        [vipButton setTitle:vip forState:UIControlStateNormal];
        [protolButton setTitle:protol forState:UIControlStateNormal];
        protolButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [submitButton setTitle:@"提交" forState:UIControlStateNormal];
        
        [_footView addSubview:submitButton];
        
        if (!self.isEditDetail) {
            
            [_footView addSubview:label1];
            [_footView addSubview:label2];
            [_footView addSubview:vipButton];
            [_footView addSubview:protolButton];
            [_footView addSubview:submitButton];
            
            CGFloat width1 = [NSString widthForString:str1 fontSize:14 andHeight:15];
            CGFloat width2 = [NSString widthForString:str2 fontSize:14 andHeight:15];
            CGFloat vipwidth = [NSString widthForString:vip fontSize:14 andHeight:15];
            [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(20);
                make.left.mas_equalTo(30);
                make.width.mas_equalTo(width1);
                make.height.mas_equalTo(15);
            }];
            [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(label1.mas_bottom).offset(25);
                make.left.equalTo(label1.mas_left);
                make.width.mas_equalTo(width2);
                make.height.mas_equalTo(15);
            }];
            [submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(label2.mas_bottom).offset(15);
                make.left.mas_equalTo(30);
                make.right.mas_equalTo(-30);
                make.height.mas_equalTo(43);
            }];
            [vipButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(label1.mas_centerY);
                make.left.equalTo(label1.mas_right).offset(8);
                make.width.mas_equalTo(vipwidth+12);
                make.height.mas_equalTo(22);
            }];
            [protolButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(label2.mas_centerY);
                make.left.equalTo(label2.mas_right);
                make.right.mas_equalTo(-10);
                make.height.mas_equalTo(22);
            }];
            
            [_footView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(_titles.count*TextField_RowHeight);
                make.left.right.mas_equalTo(0);
                make.width.mas_equalTo(IPHONE_W);
                make.height.mas_equalTo(130);
            }]; 
        }else{
            [submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(25);
                make.left.mas_equalTo(30);
                make.right.mas_equalTo(-30);
                make.height.mas_equalTo(43);
            }];
            [_footView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(_titles.count*TextField_RowHeight);
                make.left.right.mas_equalTo(0);
                make.width.mas_equalTo(IPHONE_W);
                make.height.mas_equalTo(68);
            }];
        }
    }
    return _footView;
}

- (THVipModel *)vipModel
{
    if (!_vipModel) {
        _vipModel = [[THVipModel alloc] init];
    }
    return _vipModel;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
